//
//  PhoneLoginLogic.swift
//  Casecord
//
//  Created by baozi on 2024/1/4.
//

import Foundation
class PhoneLoginLogic: BaseLogic {
    var router: Router?
    
    func toPhoneCheck(areaCode: String, phone: String) {
        Task {
            do {
                let result = try await LoginAPI
                    .isRegistered(areaCode: areaCode, phone: phone)
                    .make()
                    .async(disposeBag: self.disposeBag)
                let booleanResult = result.result?["booleanResult"].bool ?? false
                if booleanResult {
                    await router?.to(name: .passwordLogin(type: .password_login, phone: phone, areaCode: areaCode))
                } else {
                    await router?.to(name: .passwordLogin(type: .password_set, phone: phone, areaCode: areaCode))
                }
            } catch {
                await ToastManager.show(text: error.errorMessage)
            }
        }
    }
    
    deinit {
        PPLog("💀💀💀------------ \(Self.self)")
    }
}
